//
//  DKAdjustHelper.m
//  DanKU
//
//  Created by 吴斌 on 2023/12/11.
//

#import "DKAdjustHelper.h"

@implementation DKAdjustHelper
static DKAdjustHelper *defaultManager = nil;
+(DKAdjustHelper*)defaultManager{
    static dispatch_once_t token;
    dispatch_once(&token, ^{
        if(defaultManager == nil){
            defaultManager = [[self alloc] init];
        }
    });
    return defaultManager;
}
- (void)adjustFirstApp{
   NSString * firstApp =  DK_GETObject_USERDEF(NSUserDefault_FirstApp);
    if(![firstApp isEqualToString:@"1"]){//没有打点
        DKRegisterUserModel * registerUserMdl = [DKGlobalHelper defaultManager].registerUserMdl;
        DKUserBaseInfoModel * userBaseInfoMdl = [DKGlobalHelper defaultManager].userBaseInfoMdl;
        ADJEvent *event = [ADJEvent eventWithEventToken:DK_AdjustFirstOpenValue];
        [event addCallbackParameter:@"eventKey" value:DK_AdjustFirstOpenName];
        if(userBaseInfoMdl.phone.length){
            [event addCallbackParameter:@"phone" value:userBaseInfoMdl.phone];
        }else{
            [event addCallbackParameter:@"phone" value:@""];
        }
        if(registerUserMdl.userId.length){
            [event addCallbackParameter:@"userId" value:registerUserMdl.userId];
        }else{
            [event addCallbackParameter:@"userId" value:@""];
        }
        [Adjust trackEvent:event];
        DK_SETObject_USERDEF(NSUserDefault_FirstApp, @"1");
    }
}
- (void)adjustUserRegister{
    DKRegisterUserModel * registerUserMdl = [DKGlobalHelper defaultManager].registerUserMdl;
    ADJEvent *event = [ADJEvent eventWithEventToken:DK_AdjustRegisterValue];
    [event addCallbackParameter:@"eventKey" value:DK_AdjustRegisterName];
    if(registerUserMdl.phone.length){
        [event addCallbackParameter:@"phone" value:registerUserMdl.phone];
    }else{
        [event addCallbackParameter:@"phone" value:@""];
    }
    if(registerUserMdl.userId.length){
        [event addCallbackParameter:@"userId" value:registerUserMdl.userId];
    }else{
        [event addCallbackParameter:@"userId" value:@""];
    }
    [Adjust trackEvent:event];
}
- (void)adjustUserLoan{
    DKRegisterUserModel * registerUserMdl = [DKGlobalHelper defaultManager].registerUserMdl;
    DKUserBaseInfoModel * userBaseInfoMdl = [DKGlobalHelper defaultManager].userBaseInfoMdl;
    ADJEvent *event = [ADJEvent eventWithEventToken:DK_AdjustApplyOrderValue];
    [event addCallbackParameter:@"eventKey" value:DK_AdjustApplyOrderName];
    if(userBaseInfoMdl.phone.length){
        [event addCallbackParameter:@"phone" value:userBaseInfoMdl.phone];
    }else{
        [event addCallbackParameter:@"phone" value:@""];
    }
    if(registerUserMdl.userId.length){
        [event addCallbackParameter:@"userId" value:registerUserMdl.userId];
    }else{
        [event addCallbackParameter:@"userId" value:@""];
    }
    [Adjust trackEvent:event];
}
@end
